<!-- 首页 -->
<template>
	<view class="index">
		<view class="bj-image">
			<p>空港卡券联盟</p>
			<view class="tx-tit">
				<image :src="imgsrc" mode="aspectFit"></image>
				<view class="tit">
					<view class="t-tit">
						<text @click="goLogin">Hi,{{ name }}</text>
						<image @click="getpersonaldata" src="../../static/images/binaji.png" mode="aspectFit"></image>
					</view>
					<p class="f-text">省钱达人</p>
				</view>
			</view>
		</view>
		<view class="m-box">
			<view @click="getcouponmanagement" class="left">
				<view class="header">
					<image src="../../static/images/qz.png" mode="aspectFit"></image>
					<view class="r-text">
						<text>共 </text>
						<text> {{total_num}} </text>
						<text> 张 </text>
					</view>
				</view>
				<view class="footer">
					<text>我的优惠券</text>
					<image src="../../static/images/gd.png" mode="aspectFit"></image>
				</view>
			</view>
			<view class="left" @click="getcouponmanagement(0)">
				<view class="header">
					<image src="../../static/images/jjsx.png" mode="aspectFit"></image>
					<view class="r-text">
						<text> </text>
						<text> {{due_soon_num}} </text>
						<text> 张 </text>
					</view>
				</view>
				<view class="footer">
					<text>即将失效</text>
					<image src="../../static/images/gd.png" mode="aspectFit"></image>
				</view>
			</view>
		</view>
		<view class="b-box">
			<view class="bottom">
				<view class="top">
					<text>优惠券管理</text>
					<view @click="getcouponmanagement" class="right">
						<text>查看全部</text>
						<image src="../../static/images/gd.png" mode="aspectFit"></image>
					</view>
				</view>
				<view class="b-box">
					<view class="b-bottom" @click="getcouponmanagement(1)">
						<view class="item">
							<image src="../../static/images/ql.png" mode="aspectFit"></image>
							<p>未使用</p>
						</view>
					</view>
					<view class="b-bottom" @click="getcouponmanagement(2)">
						<view class="item">
							<image src="../../static/images/ysy.png" mode="aspectFit"></image>
							<p>已使用</p>
						</view>
					</view>
					<view class="b-bottom" @click="getcouponmanagement(3)">
						<view class="item">
							<image src="../../static/images/qc.png" mode="aspectFit"></image>
							<p>已失效</p>
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {shareMixins} from '../../mixins/share.js'
	export default {
		mixins:[shareMixins],
		data() {
			return {
				shareData: {
				    title: '空港卡券联盟客户端',
				    path: '/pages/index/index' ,// 分享的页面路径
					// imageUrl:'../../static/images/ywm.png'
				},
				name: '请登录',
				imgsrc: '../../static/images/sjzx.png',
				total_num: 0,
				due_soon_num: 0
			}
		},
		
		onLoad() {
			this.loginuserInfo = uni.getStorageSync('loginuserInfo')
			this.name = this.loginuserInfo.nickName
			this.imgsrc = this.loginuserInfo.avatarUrl
			if(this.name != undefined && this.name != '请登录'){
				this.wechatCentral()
			}else{
				this.$refs.uToast.show({
					title: '请先登录',
					type: 'waring'
				})
			}
		},
		methods: {
			async wechatCentral() {
				const res = await this.$myRequest({
					url: '/api/user/wechatCentral'
				}).then((res) => {
					// console.log(res.data.data.due_soon_num)
					this.total_num = res.data.data.total_num
					this.due_soon_num = res.data.data.due_soon_num
				})
			},
			getcouponmanagement(state) { //跳转优惠券管理页面
				if (this.name === undefined || this.name === '请登录') {
					this.$refs.uToast.show({
						title: '请先登录',
						type: 'waring'
					})
					setTimeout(() => {
						uni.reLaunch({
						    url: '../login/login'
						});
					}, 500)
				} else {
					uni.navigateTo({
						// url:'./couponmanagement/couponmanagement',
						url: '../../cardVoucher/pages/couponmanagement/couponmanagement?num=' + state
					})
				}
			},
			getpersonaldata() { //跳转个人资料
				if (this.name === undefined || this.name === '请登录') {
					this.$refs.uToast.show({
						title: '请先登录',
						type: 'waring'
					})
					setTimeout(() => {
						uni.reLaunch({
						    url: '../login/login'
						});
					}, 500)
				} else {
					uni.navigateTo({
						url: '../../cardVoucher/pages/personaldata/personaldata'
					})
				}
			},
			goLogin(){
				if(this.name === undefined || this.name === '请登录'){
					uni.reLaunch({
						url:'../login/login'
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.index {
		.bj-image {
			background-image: url(../../static/images/bj.png);
			background-size: cover;
			height: 514rpx;
			width: 100%;

			p {
				text-align: center;
				padding-top: 50rpx;
				font-weight: bold;
				font-size: 34rpx;
				color: #FFFFFF;
			}

			.tx-tit {
				padding: 150rpx 0 136rpx 56rpx;
				display: flex;
				align-items: center;

				image {
					width: 128rpx;
					height: 128rpx;
					border-radius: 70rpx;
					margin-right: 20rpx;
				}

				.tit {
					.t-tit {
						image {
							width: 25rpx;
							height: 25rpx;
							border-radius: 0;
						}

						text {
							margin-right: 20rpx;
							font-size: 40rpx;
							font-weight: bold;
							color: #FFFFFF;
						}
					}

					.f-text {
						background: linear-gradient(#FFEED9, #FFE7CB, #FFDDB9);
						width: 112rpx;
						height: 32rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						border-radius: 16rpx;
						margin: 0;
						padding: 0;
						font-size: 22rpx;
						color: #EC5F2F;
						margin-top: 10rpx;
					}
				}

			}
		}

		.m-box {
			padding: 0 32rpx;
			margin-top: -60rpx;
			display: flex;
			justify-content: space-between;

			.left {
				border-radius: 20rpx;
				width: 49%;
				background-color: #FFFFFF;
				padding: 22rpx 17rpx 26rpx 32rpx;

				.header {
					display: flex;
					align-items: center;
					justify-content: space-between;

					image {
						width: 80rpx;
						height: 64rpx;
					}

					.r-text {
						display: flex;
						align-items: center;

						text {
							font-size: 24rpx;
							color: #8B8B8B;
						}

						text:nth-child(2) {
							color: #3C3C3C;
							font-size: 32rpx;
							font-weight: bold;
							margin: 0 10rpx;
						}
					}
				}

				.footer {
					margin-top: 16rpx;

					text {
						font-size: 32rpx;
						font-weight: bold;
						color: #3C3C3C;
						margin-right: 20rpx;
					}

					image {
						width: 9rpx;
						height: 16rpx;
					}
				}
			}
		}

		.b-box {
			padding: 20rpx 32rpx 0 32rpx;

			.bottom {
				padding: 32rpx 32rpx 38rpx 32rpx;
				background-color: #FFEED9;
				border-radius: 20rpx;

				.top {
					display: flex;
					align-items: center;
					justify-content: space-between;

					text {
						font-size: 34rpx;
						color: #8B8B8B;
						font-weight: bold;
					}

					.right {
						text {
							font-size: 24rpx;
							color: #8B8B8B;
							font-weight: 200;
						}

						image {
							width: 10rpx;
							height: 16rpx;
							margin-left: 12rpx;
						}
					}
				}

				.b-box {
					display: flex;
					// align-items: center;
					justify-content: space-between;

					.b-bottom {
						width: 15%;

						.item {
							text-align: center;

							margin-top: 56rpx;

							image {
								width: 65rpx;
								height: 52rpx;
							}

							p {
								font-size: 28rpx;
								color: #3C3C3C;
								margin-top: 22rpx;
								font-weight: 900;
							}
						}
					}
				}

			}
		}
	}
</style>
